{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# python数据分析之Panads-1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1.1 Panads基本介绍 "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Python Data Analysis Library 或 Pandas是基于Numpy的一种工具，该工具是为了解决数据分析任务而创建的。Pandas纳入了大量库和一些标准的数据模型，提供了高效地操作大型数据集所需的工具。pandas提供了大量能使我们快速便捷地处理数据的函数和方法。**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Pandas 基本数据结构 "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "``pandas``有两种常用的基本结构：\n",
    "+ ``Series``\n",
    "    + 一维数组，与Numpy中的一维array类似。二者与Python基本的数据结构List也很接近。Series**能保存不同种数据类型**，字符串、boolean值、数字等都能保存在Series中。\n",
    "+ ``DataFrame``\n",
    "    + 二维的表格型数据结构。很多功能与R中的data.frame类似。可以将DataFrame理解为Series的容器。以下的内容主要以DataFrame为主。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1.2 Pandas库的series类型 "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "一维``Series``可以用一维列表初始化："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0    1.0\n",
      "1    3.0\n",
      "2    5.0\n",
      "3    NaN\n",
      "4    6.0\n",
      "5    8.0\n",
      "dtype: float64\n"
     ]
    }
   ],
   "source": [
    "s = pd.Series([1,3,5,np.nan,6,8])#index = ['a','b','c','d','x','y'])设置索引，np.nan设置空值\n",
    "print(s)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "默认情况下，``Series``的下标都是数字（可以使用额外参数指定），类型是统一的。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 索引——数据的行标签 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "RangeIndex(start=0, stop=6, step=1)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s.index #从0到6（不含），1为步长"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 1.,  3.,  5., nan,  6.,  8.])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s.values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "nan"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s[3]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "切片操作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2    5.0\n",
       "3    NaN\n",
       "4    6.0\n",
       "dtype: float64"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s[2:5] #左闭右开"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    1.0\n",
       "2    5.0\n",
       "4    6.0\n",
       "dtype: float64"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s[::2]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "索引赋值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "索引\n",
       "0    1.0\n",
       "1    3.0\n",
       "2    5.0\n",
       "3    NaN\n",
       "4    6.0\n",
       "5    8.0\n",
       "dtype: float64"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s.index.name = '索引'\n",
    "s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "a    1.0\n",
       "b    3.0\n",
       "c    5.0\n",
       "d    NaN\n",
       "e    6.0\n",
       "f    8.0\n",
       "dtype: float64"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s.index = list('abcdef')\n",
    "s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "a    1.0\n",
       "c    5.0\n",
       "dtype: float64"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s['a':'c':2] #依据自己定义的数据类型进行切片，不是左闭右开了"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1.3 Pandas库的DataFrame类型\n",
    "\n",
    "``DataFrame``则是个二维结构，这里首先构造一组时间序列，作为我们第一维的下标："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "DatetimeIndex(['2018-01-01', '2018-01-02', '2018-01-03', '2018-01-04',\n",
      "               '2018-01-05', '2018-01-06'],\n",
      "              dtype='datetime64[ns]', freq='D')\n"
     ]
    }
   ],
   "source": [
    "date = pd.date_range(\"20180101\", periods = 6)\n",
    "print(date)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "然后创建一个``DataFrame``结构："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2018-01-01</th>\n",
       "      <td>-0.117775</td>\n",
       "      <td>1.649426</td>\n",
       "      <td>0.764780</td>\n",
       "      <td>0.204315</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-01-02</th>\n",
       "      <td>-0.971404</td>\n",
       "      <td>0.775947</td>\n",
       "      <td>0.852739</td>\n",
       "      <td>0.658201</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-01-03</th>\n",
       "      <td>0.759895</td>\n",
       "      <td>-0.009870</td>\n",
       "      <td>-1.317165</td>\n",
       "      <td>-0.318906</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-01-04</th>\n",
       "      <td>1.329905</td>\n",
       "      <td>0.628712</td>\n",
       "      <td>2.402299</td>\n",
       "      <td>0.224211</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-01-05</th>\n",
       "      <td>0.625181</td>\n",
       "      <td>1.047354</td>\n",
       "      <td>-1.138055</td>\n",
       "      <td>0.676203</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-01-06</th>\n",
       "      <td>0.483537</td>\n",
       "      <td>1.487613</td>\n",
       "      <td>0.927196</td>\n",
       "      <td>-1.256073</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   A         B         C         D\n",
       "2018-01-01 -0.117775  1.649426  0.764780  0.204315\n",
       "2018-01-02 -0.971404  0.775947  0.852739  0.658201\n",
       "2018-01-03  0.759895 -0.009870 -1.317165 -0.318906\n",
       "2018-01-04  1.329905  0.628712  2.402299  0.224211\n",
       "2018-01-05  0.625181  1.047354 -1.138055  0.676203\n",
       "2018-01-06  0.483537  1.487613  0.927196 -1.256073"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame(np.random.randn(6,4), index = date, columns = list(\"ABCD\"))\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "默认情况下，如果不指定``index``参数和``columns``，那么它们的值将从用0开始的数字替代。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>-0.348590</td>\n",
       "      <td>0.469809</td>\n",
       "      <td>0.583148</td>\n",
       "      <td>-0.280558</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1.459419</td>\n",
       "      <td>-0.492431</td>\n",
       "      <td>-1.189225</td>\n",
       "      <td>-0.800349</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>-1.022773</td>\n",
       "      <td>0.716410</td>\n",
       "      <td>1.125772</td>\n",
       "      <td>1.567633</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1.240480</td>\n",
       "      <td>2.391370</td>\n",
       "      <td>-1.386115</td>\n",
       "      <td>-1.502477</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1.819155</td>\n",
       "      <td>-1.059532</td>\n",
       "      <td>-1.252225</td>\n",
       "      <td>0.610130</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>0.143627</td>\n",
       "      <td>0.013160</td>\n",
       "      <td>-0.927291</td>\n",
       "      <td>-1.067693</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          0         1         2         3\n",
       "0 -0.348590  0.469809  0.583148 -0.280558\n",
       "1  1.459419 -0.492431 -1.189225 -0.800349\n",
       "2 -1.022773  0.716410  1.125772  1.567633\n",
       "3  1.240480  2.391370 -1.386115 -1.502477\n",
       "4  1.819155 -1.059532 -1.252225  0.610130\n",
       "5  0.143627  0.013160 -0.927291 -1.067693"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame(np.random.randn(6,4))\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "除了向``DataFrame``中传入二维数组，我们也可以使用字典传入数据："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "      <th>E</th>\n",
       "      <th>F</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1.0</td>\n",
       "      <td>2018-10-01</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3</td>\n",
       "      <td>test</td>\n",
       "      <td>abc</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1.0</td>\n",
       "      <td>2018-10-01</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3</td>\n",
       "      <td>train</td>\n",
       "      <td>abc</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1.0</td>\n",
       "      <td>2018-10-01</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3</td>\n",
       "      <td>test</td>\n",
       "      <td>abc</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1.0</td>\n",
       "      <td>2018-10-01</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3</td>\n",
       "      <td>train</td>\n",
       "      <td>abc</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     A          B    C  D      E    F\n",
       "0  1.0 2018-10-01  1.0  3   test  abc\n",
       "1  1.0 2018-10-01  1.0  3  train  abc\n",
       "2  1.0 2018-10-01  1.0  3   test  abc\n",
       "3  1.0 2018-10-01  1.0  3  train  abc"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2 = pd.DataFrame({'A':1.,'B':pd.Timestamp(\"20181001\"),'C':pd.Series(1,index = list(range(4)),dtype = float),'D':np.array([3]*4, dtype = int),'E':pd.Categorical([\"test\",\"train\",\"test\",\"train\"]),'F':\"abc\"}) #B:时间戳,E分类类型\n",
    "df2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "A           float64\n",
       "B    datetime64[ns]\n",
       "C           float64\n",
       "D             int64\n",
       "E          category\n",
       "F            object\n",
       "dtype: object"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2.dtypes #查看各个列的数据类型"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "字典的每个``key``代表一列，其``value``可以是各种能够转化为``Series``的对象。\n",
    "\n",
    "与``Series``要求所有的类型都一致不同，``DataFrame``只要求每一列数据的格式相同。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 查看数据 "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 头尾数据"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "``head``和``tail``方法可以分别查看最前面几行和最后面几行的数据（默认为5）："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>-0.348590</td>\n",
       "      <td>0.469809</td>\n",
       "      <td>0.583148</td>\n",
       "      <td>-0.280558</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1.459419</td>\n",
       "      <td>-0.492431</td>\n",
       "      <td>-1.189225</td>\n",
       "      <td>-0.800349</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>-1.022773</td>\n",
       "      <td>0.716410</td>\n",
       "      <td>1.125772</td>\n",
       "      <td>1.567633</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1.240480</td>\n",
       "      <td>2.391370</td>\n",
       "      <td>-1.386115</td>\n",
       "      <td>-1.502477</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1.819155</td>\n",
       "      <td>-1.059532</td>\n",
       "      <td>-1.252225</td>\n",
       "      <td>0.610130</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          0         1         2         3\n",
       "0 -0.348590  0.469809  0.583148 -0.280558\n",
       "1  1.459419 -0.492431 -1.189225 -0.800349\n",
       "2 -1.022773  0.716410  1.125772  1.567633\n",
       "3  1.240480  2.391370 -1.386115 -1.502477\n",
       "4  1.819155 -1.059532 -1.252225  0.610130"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "最后3行："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1.240480</td>\n",
       "      <td>2.391370</td>\n",
       "      <td>-1.386115</td>\n",
       "      <td>-1.502477</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1.819155</td>\n",
       "      <td>-1.059532</td>\n",
       "      <td>-1.252225</td>\n",
       "      <td>0.610130</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>0.143627</td>\n",
       "      <td>0.013160</td>\n",
       "      <td>-0.927291</td>\n",
       "      <td>-1.067693</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          0         1         2         3\n",
       "3  1.240480  2.391370 -1.386115 -1.502477\n",
       "4  1.819155 -1.059532 -1.252225  0.610130\n",
       "5  0.143627  0.013160 -0.927291 -1.067693"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.tail(3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 下标，列标，数据 "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "下标使用``index``属性查看："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "RangeIndex(start=0, stop=6, step=1)"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.index"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "列标使用``columns``属性查看："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "RangeIndex(start=0, stop=4, step=1)"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.columns"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "数据值使用``values``查看："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[-0.34858954,  0.46980885,  0.58314771, -0.2805577 ],\n",
       "       [ 1.45941852, -0.49243077, -1.18922459, -0.80034854],\n",
       "       [-1.02277334,  0.71641012,  1.12577176,  1.56763335],\n",
       "       [ 1.24047998,  2.39136951, -1.38611469, -1.502477  ],\n",
       "       [ 1.81915534, -1.05953245, -1.25222481,  0.61012975],\n",
       "       [ 0.14362654,  0.01315995, -0.92729097, -1.06769336]])"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.values"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1.4 pandas读取数据及数据操作 "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "我们将以豆瓣的电影数据作为我们深入了解Pandas的一个示例。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "ename": "FileNotFoundError",
     "evalue": "[Errno 2] No such file or directory: 'C:\\\\Users\\\\Lovetianyi\\\\Desktop\\\\python\\\\作业3\\\\豆瓣电影数据.xlsx'",
     "output_type": "error",
     "traceback": [
      "\u001B[0;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[0;31mFileNotFoundError\u001B[0m                         Traceback (most recent call last)",
      "\u001B[0;32m/var/folders/fj/074djdr13178c4hpdlwt37r00000gp/T/ipykernel_3156/2497221959.py\u001B[0m in \u001B[0;36m<module>\u001B[0;34m\u001B[0m\n\u001B[0;32m----> 1\u001B[0;31m \u001B[0mdf\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mpd\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mread_excel\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34mr\"C:\\Users\\Lovetianyi\\Desktop\\python\\作业3\\豆瓣电影数据.xlsx\"\u001B[0m\u001B[0;34m,\u001B[0m\u001B[0mindex_col\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0;36m0\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m      2\u001B[0m \u001B[0;31m#csv:read_csv;绝对路径或相对路径默认在当前文件夹下。r告诉编译器不需要转义\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m      3\u001B[0m \u001B[0;31m#具体其它参数可以去查帮助文档 ?pd.read_excel\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0;32m~/opt/anaconda3/envs/py37-aiops/lib/python3.7/site-packages/pandas/util/_decorators.py\u001B[0m in \u001B[0;36mwrapper\u001B[0;34m(*args, **kwargs)\u001B[0m\n\u001B[1;32m    309\u001B[0m                     \u001B[0mstacklevel\u001B[0m\u001B[0;34m=\u001B[0m\u001B[0mstacklevel\u001B[0m\u001B[0;34m,\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m    310\u001B[0m                 )\n\u001B[0;32m--> 311\u001B[0;31m             \u001B[0;32mreturn\u001B[0m \u001B[0mfunc\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m*\u001B[0m\u001B[0margs\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0;34m**\u001B[0m\u001B[0mkwargs\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m    312\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m    313\u001B[0m         \u001B[0;32mreturn\u001B[0m \u001B[0mwrapper\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0;32m~/opt/anaconda3/envs/py37-aiops/lib/python3.7/site-packages/pandas/io/excel/_base.py\u001B[0m in \u001B[0;36mread_excel\u001B[0;34m(io, sheet_name, header, names, index_col, usecols, squeeze, dtype, engine, converters, true_values, false_values, skiprows, nrows, na_values, keep_default_na, na_filter, verbose, parse_dates, date_parser, thousands, comment, skipfooter, convert_float, mangle_dupe_cols, storage_options)\u001B[0m\n\u001B[1;32m    362\u001B[0m     \u001B[0;32mif\u001B[0m \u001B[0;32mnot\u001B[0m \u001B[0misinstance\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mio\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mExcelFile\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m    363\u001B[0m         \u001B[0mshould_close\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0;32mTrue\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m--> 364\u001B[0;31m         \u001B[0mio\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mExcelFile\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mio\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mstorage_options\u001B[0m\u001B[0;34m=\u001B[0m\u001B[0mstorage_options\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mengine\u001B[0m\u001B[0;34m=\u001B[0m\u001B[0mengine\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m    365\u001B[0m     \u001B[0;32melif\u001B[0m \u001B[0mengine\u001B[0m \u001B[0;32mand\u001B[0m \u001B[0mengine\u001B[0m \u001B[0;34m!=\u001B[0m \u001B[0mio\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mengine\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m    366\u001B[0m         raise ValueError(\n",
      "\u001B[0;32m~/opt/anaconda3/envs/py37-aiops/lib/python3.7/site-packages/pandas/io/excel/_base.py\u001B[0m in \u001B[0;36m__init__\u001B[0;34m(self, path_or_buffer, engine, storage_options)\u001B[0m\n\u001B[1;32m   1190\u001B[0m             \u001B[0;32melse\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m   1191\u001B[0m                 ext = inspect_excel_format(\n\u001B[0;32m-> 1192\u001B[0;31m                     \u001B[0mcontent_or_path\u001B[0m\u001B[0;34m=\u001B[0m\u001B[0mpath_or_buffer\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mstorage_options\u001B[0m\u001B[0;34m=\u001B[0m\u001B[0mstorage_options\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m   1193\u001B[0m                 )\n\u001B[1;32m   1194\u001B[0m                 \u001B[0;32mif\u001B[0m \u001B[0mext\u001B[0m \u001B[0;32mis\u001B[0m \u001B[0;32mNone\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0;32m~/opt/anaconda3/envs/py37-aiops/lib/python3.7/site-packages/pandas/io/excel/_base.py\u001B[0m in \u001B[0;36minspect_excel_format\u001B[0;34m(content_or_path, storage_options)\u001B[0m\n\u001B[1;32m   1069\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m   1070\u001B[0m     with get_handle(\n\u001B[0;32m-> 1071\u001B[0;31m         \u001B[0mcontent_or_path\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0;34m\"rb\"\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mstorage_options\u001B[0m\u001B[0;34m=\u001B[0m\u001B[0mstorage_options\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mis_text\u001B[0m\u001B[0;34m=\u001B[0m\u001B[0;32mFalse\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m   1072\u001B[0m     ) as handle:\n\u001B[1;32m   1073\u001B[0m         \u001B[0mstream\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mhandle\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mhandle\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0;32m~/opt/anaconda3/envs/py37-aiops/lib/python3.7/site-packages/pandas/io/common.py\u001B[0m in \u001B[0;36mget_handle\u001B[0;34m(path_or_buf, mode, encoding, compression, memory_map, is_text, errors, storage_options)\u001B[0m\n\u001B[1;32m    709\u001B[0m         \u001B[0;32melse\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m    710\u001B[0m             \u001B[0;31m# Binary mode\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m--> 711\u001B[0;31m             \u001B[0mhandle\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mopen\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mhandle\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mioargs\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mmode\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m    712\u001B[0m         \u001B[0mhandles\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mappend\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mhandle\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m    713\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0;31mFileNotFoundError\u001B[0m: [Errno 2] No such file or directory: 'C:\\\\Users\\\\Lovetianyi\\\\Desktop\\\\python\\\\作业3\\\\豆瓣电影数据.xlsx'"
     ]
    }
   ],
   "source": [
    "df = pd.read_excel(r\"C:\\Users\\Lovetianyi\\Desktop\\python\\作业3\\豆瓣电影数据.xlsx\",index_col = 0) \n",
    "#csv:read_csv;绝对路径或相对路径默认在当前文件夹下。r告诉编译器不需要转义\n",
    "#具体其它参数可以去查帮助文档 ?pd.read_excel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 行操作 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0   -0.348590\n",
       "1    0.469809\n",
       "2    0.583148\n",
       "3   -0.280558\n",
       "Name: 0, dtype: float64"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.iloc[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>-0.348590</td>\n",
       "      <td>0.469809</td>\n",
       "      <td>0.583148</td>\n",
       "      <td>-0.280558</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1.459419</td>\n",
       "      <td>-0.492431</td>\n",
       "      <td>-1.189225</td>\n",
       "      <td>-0.800349</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>-1.022773</td>\n",
       "      <td>0.716410</td>\n",
       "      <td>1.125772</td>\n",
       "      <td>1.567633</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1.240480</td>\n",
       "      <td>2.391370</td>\n",
       "      <td>-1.386115</td>\n",
       "      <td>-1.502477</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1.819155</td>\n",
       "      <td>-1.059532</td>\n",
       "      <td>-1.252225</td>\n",
       "      <td>0.610130</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          0         1         2         3\n",
       "0 -0.348590  0.469809  0.583148 -0.280558\n",
       "1  1.459419 -0.492431 -1.189225 -0.800349\n",
       "2 -1.022773  0.716410  1.125772  1.567633\n",
       "3  1.240480  2.391370 -1.386115 -1.502477\n",
       "4  1.819155 -1.059532 -1.252225  0.610130"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.iloc[0:5] #左闭右开"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "也可以使用loc"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>-0.348590</td>\n",
       "      <td>0.469809</td>\n",
       "      <td>0.583148</td>\n",
       "      <td>-0.280558</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1.459419</td>\n",
       "      <td>-0.492431</td>\n",
       "      <td>-1.189225</td>\n",
       "      <td>-0.800349</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>-1.022773</td>\n",
       "      <td>0.716410</td>\n",
       "      <td>1.125772</td>\n",
       "      <td>1.567633</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1.240480</td>\n",
       "      <td>2.391370</td>\n",
       "      <td>-1.386115</td>\n",
       "      <td>-1.502477</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1.819155</td>\n",
       "      <td>-1.059532</td>\n",
       "      <td>-1.252225</td>\n",
       "      <td>0.610130</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>0.143627</td>\n",
       "      <td>0.013160</td>\n",
       "      <td>-0.927291</td>\n",
       "      <td>-1.067693</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          0         1         2         3\n",
       "0 -0.348590  0.469809  0.583148 -0.280558\n",
       "1  1.459419 -0.492431 -1.189225 -0.800349\n",
       "2 -1.022773  0.716410  1.125772  1.567633\n",
       "3  1.240480  2.391370 -1.386115 -1.502477\n",
       "4  1.819155 -1.059532 -1.252225  0.610130\n",
       "5  0.143627  0.013160 -0.927291 -1.067693"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[0:5] #不是左闭右开"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "####  添加一行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "dit = {\"名字\":\"复仇者联盟3\",\"投票人数\":123456,\"类型\":\"剧情/科幻\",\"产地\":\"美国\",\"上映时间\":\"2018-05-04 00:00:00\",\"时长\":142,\"年代\":2018,\"评分\":np.nan,\"首映地点\":\"美国\"}\n",
    "s = pd.Series(dit)\n",
    "s.name = 38738"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "名字                   复仇者联盟3\n",
       "投票人数                 123456\n",
       "类型                    剧情/科幻\n",
       "产地                       美国\n",
       "上映时间    2018-05-04 00:00:00\n",
       "时长                      142\n",
       "年代                     2018\n",
       "评分                      NaN\n",
       "首映地点                     美国\n",
       "Name: 38738, dtype: object"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>上映时间</th>\n",
       "      <th>产地</th>\n",
       "      <th>名字</th>\n",
       "      <th>年代</th>\n",
       "      <th>投票人数</th>\n",
       "      <th>时长</th>\n",
       "      <th>类型</th>\n",
       "      <th>评分</th>\n",
       "      <th>首映地点</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>-1.022773</td>\n",
       "      <td>0.716410</td>\n",
       "      <td>1.125772</td>\n",
       "      <td>1.567633</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1.240480</td>\n",
       "      <td>2.391370</td>\n",
       "      <td>-1.386115</td>\n",
       "      <td>-1.502477</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1.819155</td>\n",
       "      <td>-1.059532</td>\n",
       "      <td>-1.252225</td>\n",
       "      <td>0.610130</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>0.143627</td>\n",
       "      <td>0.013160</td>\n",
       "      <td>-0.927291</td>\n",
       "      <td>-1.067693</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>38738</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2018-05-04 00:00:00</td>\n",
       "      <td>美国</td>\n",
       "      <td>复仇者联盟3</td>\n",
       "      <td>2018.0</td>\n",
       "      <td>123456.0</td>\n",
       "      <td>142.0</td>\n",
       "      <td>剧情/科幻</td>\n",
       "      <td>NaN</td>\n",
       "      <td>美国</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              0         1         2         3                 上映时间   产地  \\\n",
       "2     -1.022773  0.716410  1.125772  1.567633                  NaN  NaN   \n",
       "3      1.240480  2.391370 -1.386115 -1.502477                  NaN  NaN   \n",
       "4      1.819155 -1.059532 -1.252225  0.610130                  NaN  NaN   \n",
       "5      0.143627  0.013160 -0.927291 -1.067693                  NaN  NaN   \n",
       "38738       NaN       NaN       NaN       NaN  2018-05-04 00:00:00   美国   \n",
       "\n",
       "           名字      年代      投票人数     时长     类型  评分 首映地点  \n",
       "2         NaN     NaN       NaN    NaN    NaN NaN  NaN  \n",
       "3         NaN     NaN       NaN    NaN    NaN NaN  NaN  \n",
       "4         NaN     NaN       NaN    NaN    NaN NaN  NaN  \n",
       "5         NaN     NaN       NaN    NaN    NaN NaN  NaN  \n",
       "38738  复仇者联盟3  2018.0  123456.0  142.0  剧情/科幻 NaN   美国  "
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = df.append(s) #覆盖掉原来的数据重新进行赋值\n",
    "df[-5:]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 删除一行 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>上映时间</th>\n",
       "      <th>产地</th>\n",
       "      <th>名字</th>\n",
       "      <th>年代</th>\n",
       "      <th>投票人数</th>\n",
       "      <th>时长</th>\n",
       "      <th>类型</th>\n",
       "      <th>评分</th>\n",
       "      <th>首映地点</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1.459419</td>\n",
       "      <td>-0.492431</td>\n",
       "      <td>-1.189225</td>\n",
       "      <td>-0.800349</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>-1.022773</td>\n",
       "      <td>0.716410</td>\n",
       "      <td>1.125772</td>\n",
       "      <td>1.567633</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1.240480</td>\n",
       "      <td>2.391370</td>\n",
       "      <td>-1.386115</td>\n",
       "      <td>-1.502477</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1.819155</td>\n",
       "      <td>-1.059532</td>\n",
       "      <td>-1.252225</td>\n",
       "      <td>0.610130</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>0.143627</td>\n",
       "      <td>0.013160</td>\n",
       "      <td>-0.927291</td>\n",
       "      <td>-1.067693</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          0         1         2         3 上映时间   产地   名字  年代  投票人数  时长   类型  \\\n",
       "1  1.459419 -0.492431 -1.189225 -0.800349  NaN  NaN  NaN NaN   NaN NaN  NaN   \n",
       "2 -1.022773  0.716410  1.125772  1.567633  NaN  NaN  NaN NaN   NaN NaN  NaN   \n",
       "3  1.240480  2.391370 -1.386115 -1.502477  NaN  NaN  NaN NaN   NaN NaN  NaN   \n",
       "4  1.819155 -1.059532 -1.252225  0.610130  NaN  NaN  NaN NaN   NaN NaN  NaN   \n",
       "5  0.143627  0.013160 -0.927291 -1.067693  NaN  NaN  NaN NaN   NaN NaN  NaN   \n",
       "\n",
       "   评分 首映地点  \n",
       "1 NaN  NaN  \n",
       "2 NaN  NaN  \n",
       "3 NaN  NaN  \n",
       "4 NaN  NaN  \n",
       "5 NaN  NaN  "
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = df.drop([38738])\n",
    "df[-5:]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 列操作 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index([0, 1, 2, 3, '上映时间', '产地', '名字', '年代', '投票人数', '时长', '类型', '评分', '首映地点'], dtype='object')"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    NaN\n",
       "1    NaN\n",
       "2    NaN\n",
       "3    NaN\n",
       "4    NaN\n",
       "Name: 名字, dtype: object"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[\"名字\"][:5] #后面中括号表示只想看到的行数，下同"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>名字</th>\n",
       "      <th>类型</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    名字   类型\n",
       "0  NaN  NaN\n",
       "1  NaN  NaN\n",
       "2  NaN  NaN\n",
       "3  NaN  NaN\n",
       "4  NaN  NaN"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[[\"名字\",\"类型\"]][:5]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 增加一列 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>上映时间</th>\n",
       "      <th>产地</th>\n",
       "      <th>名字</th>\n",
       "      <th>年代</th>\n",
       "      <th>投票人数</th>\n",
       "      <th>时长</th>\n",
       "      <th>类型</th>\n",
       "      <th>评分</th>\n",
       "      <th>首映地点</th>\n",
       "      <th>序号</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>-0.348590</td>\n",
       "      <td>0.469809</td>\n",
       "      <td>0.583148</td>\n",
       "      <td>-0.280558</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1.459419</td>\n",
       "      <td>-0.492431</td>\n",
       "      <td>-1.189225</td>\n",
       "      <td>-0.800349</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>-1.022773</td>\n",
       "      <td>0.716410</td>\n",
       "      <td>1.125772</td>\n",
       "      <td>1.567633</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1.240480</td>\n",
       "      <td>2.391370</td>\n",
       "      <td>-1.386115</td>\n",
       "      <td>-1.502477</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1.819155</td>\n",
       "      <td>-1.059532</td>\n",
       "      <td>-1.252225</td>\n",
       "      <td>0.610130</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          0         1         2         3 上映时间   产地   名字  年代  投票人数  时长   类型  \\\n",
       "0 -0.348590  0.469809  0.583148 -0.280558  NaN  NaN  NaN NaN   NaN NaN  NaN   \n",
       "1  1.459419 -0.492431 -1.189225 -0.800349  NaN  NaN  NaN NaN   NaN NaN  NaN   \n",
       "2 -1.022773  0.716410  1.125772  1.567633  NaN  NaN  NaN NaN   NaN NaN  NaN   \n",
       "3  1.240480  2.391370 -1.386115 -1.502477  NaN  NaN  NaN NaN   NaN NaN  NaN   \n",
       "4  1.819155 -1.059532 -1.252225  0.610130  NaN  NaN  NaN NaN   NaN NaN  NaN   \n",
       "\n",
       "   评分 首映地点  序号  \n",
       "0 NaN  NaN   1  \n",
       "1 NaN  NaN   2  \n",
       "2 NaN  NaN   3  \n",
       "3 NaN  NaN   4  \n",
       "4 NaN  NaN   5  "
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[\"序号\"] = range(1,len(df)+1) #生成序号的基本方式\n",
    "df[:5]\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 删除一列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>名字</th>\n",
       "      <th>投票人数</th>\n",
       "      <th>类型</th>\n",
       "      <th>产地</th>\n",
       "      <th>上映时间</th>\n",
       "      <th>时长</th>\n",
       "      <th>年代</th>\n",
       "      <th>评分</th>\n",
       "      <th>首映地点</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>肖申克的救赎</td>\n",
       "      <td>692795.0</td>\n",
       "      <td>剧情/犯罪</td>\n",
       "      <td>美国</td>\n",
       "      <td>1994-09-10 00:00:00</td>\n",
       "      <td>142</td>\n",
       "      <td>1994</td>\n",
       "      <td>9.6</td>\n",
       "      <td>多伦多电影节</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>控方证人</td>\n",
       "      <td>42995.0</td>\n",
       "      <td>剧情/悬疑/犯罪</td>\n",
       "      <td>美国</td>\n",
       "      <td>1957-12-17 00:00:00</td>\n",
       "      <td>116</td>\n",
       "      <td>1957</td>\n",
       "      <td>9.5</td>\n",
       "      <td>美国</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>美丽人生</td>\n",
       "      <td>327855.0</td>\n",
       "      <td>剧情/喜剧/爱情</td>\n",
       "      <td>意大利</td>\n",
       "      <td>1997-12-20 00:00:00</td>\n",
       "      <td>116</td>\n",
       "      <td>1997</td>\n",
       "      <td>9.5</td>\n",
       "      <td>意大利</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>阿甘正传</td>\n",
       "      <td>580897.0</td>\n",
       "      <td>剧情/爱情</td>\n",
       "      <td>美国</td>\n",
       "      <td>1994-06-23 00:00:00</td>\n",
       "      <td>142</td>\n",
       "      <td>1994</td>\n",
       "      <td>9.4</td>\n",
       "      <td>洛杉矶首映</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>霸王别姬</td>\n",
       "      <td>478523.0</td>\n",
       "      <td>剧情/爱情/同性</td>\n",
       "      <td>中国大陆</td>\n",
       "      <td>1993-01-01 00:00:00</td>\n",
       "      <td>171</td>\n",
       "      <td>1993</td>\n",
       "      <td>9.4</td>\n",
       "      <td>香港</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       名字      投票人数        类型    产地                 上映时间   时长    年代   评分  \\\n",
       "0  肖申克的救赎  692795.0     剧情/犯罪    美国  1994-09-10 00:00:00  142  1994  9.6   \n",
       "1    控方证人   42995.0  剧情/悬疑/犯罪    美国  1957-12-17 00:00:00  116  1957  9.5   \n",
       "2   美丽人生   327855.0  剧情/喜剧/爱情   意大利  1997-12-20 00:00:00  116  1997  9.5   \n",
       "3    阿甘正传  580897.0     剧情/爱情    美国  1994-06-23 00:00:00  142  1994  9.4   \n",
       "4    霸王别姬  478523.0  剧情/爱情/同性  中国大陆  1993-01-01 00:00:00  171  1993  9.4   \n",
       "\n",
       "     首映地点  \n",
       "0  多伦多电影节  \n",
       "1      美国  \n",
       "2     意大利  \n",
       "3   洛杉矶首映  \n",
       "4      香港  "
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = df.drop(\"序号\",axis = 1) #axis指定方向，0为行1为列，默认为0\n",
    "df[:5]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 通过标签选择数据\n",
    "``df.loc[[index],[colunm]]``通过标签选择数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'控方证人'"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[1,\"名字\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>名字</th>\n",
       "      <th>评分</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>控方证人</td>\n",
       "      <td>9.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>阿甘正传</td>\n",
       "      <td>9.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>泰坦尼克号</td>\n",
       "      <td>9.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>新世纪福音战士剧场版：Air/真心为你 新世紀エヴァンゲリオン劇場版 Ai</td>\n",
       "      <td>9.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>这个杀手不太冷</td>\n",
       "      <td>9.4</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                      名字   评分\n",
       "1                                   控方证人  9.5\n",
       "3                                   阿甘正传  9.4\n",
       "5                                 泰坦尼克号   9.4\n",
       "7  新世纪福音战士剧场版：Air/真心为你 新世紀エヴァンゲリオン劇場版 Ai  9.4\n",
       "9                               这个杀手不太冷   9.4"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[[1,3,5,7,9],[\"名字\",\"评分\"]] #多行跳行多列跳列选择"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 条件选择 "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 选取产地为美国的所有电影 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>名字</th>\n",
       "      <th>投票人数</th>\n",
       "      <th>类型</th>\n",
       "      <th>产地</th>\n",
       "      <th>上映时间</th>\n",
       "      <th>时长</th>\n",
       "      <th>年代</th>\n",
       "      <th>评分</th>\n",
       "      <th>首映地点</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>肖申克的救赎</td>\n",
       "      <td>692795.0</td>\n",
       "      <td>剧情/犯罪</td>\n",
       "      <td>美国</td>\n",
       "      <td>1994-09-10 00:00:00</td>\n",
       "      <td>142</td>\n",
       "      <td>1994</td>\n",
       "      <td>9.6</td>\n",
       "      <td>多伦多电影节</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>控方证人</td>\n",
       "      <td>42995.0</td>\n",
       "      <td>剧情/悬疑/犯罪</td>\n",
       "      <td>美国</td>\n",
       "      <td>1957-12-17 00:00:00</td>\n",
       "      <td>116</td>\n",
       "      <td>1957</td>\n",
       "      <td>9.5</td>\n",
       "      <td>美国</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>阿甘正传</td>\n",
       "      <td>580897.0</td>\n",
       "      <td>剧情/爱情</td>\n",
       "      <td>美国</td>\n",
       "      <td>1994-06-23 00:00:00</td>\n",
       "      <td>142</td>\n",
       "      <td>1994</td>\n",
       "      <td>9.4</td>\n",
       "      <td>洛杉矶首映</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>泰坦尼克号</td>\n",
       "      <td>157074.0</td>\n",
       "      <td>剧情/爱情/灾难</td>\n",
       "      <td>美国</td>\n",
       "      <td>2012-04-10 00:00:00</td>\n",
       "      <td>194</td>\n",
       "      <td>2012</td>\n",
       "      <td>9.4</td>\n",
       "      <td>中国大陆</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>辛德勒的名单</td>\n",
       "      <td>306904.0</td>\n",
       "      <td>剧情/历史/战争</td>\n",
       "      <td>美国</td>\n",
       "      <td>1993-11-30 00:00:00</td>\n",
       "      <td>195</td>\n",
       "      <td>1993</td>\n",
       "      <td>9.4</td>\n",
       "      <td>华盛顿首映</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       名字      投票人数        类型  产地                 上映时间   时长    年代   评分    首映地点\n",
       "0  肖申克的救赎  692795.0     剧情/犯罪  美国  1994-09-10 00:00:00  142  1994  9.6  多伦多电影节\n",
       "1    控方证人   42995.0  剧情/悬疑/犯罪  美国  1957-12-17 00:00:00  116  1957  9.5      美国\n",
       "3    阿甘正传  580897.0     剧情/爱情  美国  1994-06-23 00:00:00  142  1994  9.4   洛杉矶首映\n",
       "5  泰坦尼克号   157074.0  剧情/爱情/灾难  美国  2012-04-10 00:00:00  194  2012  9.4    中国大陆\n",
       "6  辛德勒的名单  306904.0  剧情/历史/战争  美国  1993-11-30 00:00:00  195  1993  9.4   华盛顿首映"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[df[\"产地\"] == \"美国\"][:5] #内部为bool"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 选取产地为美国的所有电影，并且评分大于9分的电影"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>名字</th>\n",
       "      <th>投票人数</th>\n",
       "      <th>类型</th>\n",
       "      <th>产地</th>\n",
       "      <th>上映时间</th>\n",
       "      <th>时长</th>\n",
       "      <th>年代</th>\n",
       "      <th>评分</th>\n",
       "      <th>首映地点</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>肖申克的救赎</td>\n",
       "      <td>692795.0</td>\n",
       "      <td>剧情/犯罪</td>\n",
       "      <td>美国</td>\n",
       "      <td>1994-09-10 00:00:00</td>\n",
       "      <td>142</td>\n",
       "      <td>1994</td>\n",
       "      <td>9.6</td>\n",
       "      <td>多伦多电影节</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>控方证人</td>\n",
       "      <td>42995.0</td>\n",
       "      <td>剧情/悬疑/犯罪</td>\n",
       "      <td>美国</td>\n",
       "      <td>1957-12-17 00:00:00</td>\n",
       "      <td>116</td>\n",
       "      <td>1957</td>\n",
       "      <td>9.5</td>\n",
       "      <td>美国</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>阿甘正传</td>\n",
       "      <td>580897.0</td>\n",
       "      <td>剧情/爱情</td>\n",
       "      <td>美国</td>\n",
       "      <td>1994-06-23 00:00:00</td>\n",
       "      <td>142</td>\n",
       "      <td>1994</td>\n",
       "      <td>9.4</td>\n",
       "      <td>洛杉矶首映</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>泰坦尼克号</td>\n",
       "      <td>157074.0</td>\n",
       "      <td>剧情/爱情/灾难</td>\n",
       "      <td>美国</td>\n",
       "      <td>2012-04-10 00:00:00</td>\n",
       "      <td>194</td>\n",
       "      <td>2012</td>\n",
       "      <td>9.4</td>\n",
       "      <td>中国大陆</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>辛德勒的名单</td>\n",
       "      <td>306904.0</td>\n",
       "      <td>剧情/历史/战争</td>\n",
       "      <td>美国</td>\n",
       "      <td>1993-11-30 00:00:00</td>\n",
       "      <td>195</td>\n",
       "      <td>1993</td>\n",
       "      <td>9.4</td>\n",
       "      <td>华盛顿首映</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       名字      投票人数        类型  产地                 上映时间   时长    年代   评分    首映地点\n",
       "0  肖申克的救赎  692795.0     剧情/犯罪  美国  1994-09-10 00:00:00  142  1994  9.6  多伦多电影节\n",
       "1    控方证人   42995.0  剧情/悬疑/犯罪  美国  1957-12-17 00:00:00  116  1957  9.5      美国\n",
       "3    阿甘正传  580897.0     剧情/爱情  美国  1994-06-23 00:00:00  142  1994  9.4   洛杉矶首映\n",
       "5  泰坦尼克号   157074.0  剧情/爱情/灾难  美国  2012-04-10 00:00:00  194  2012  9.4    中国大陆\n",
       "6  辛德勒的名单  306904.0  剧情/历史/战争  美国  1993-11-30 00:00:00  195  1993  9.4   华盛顿首映"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[(df.产地 == \"美国\") & (df.评分 > 9)][:5] #df.标签:更简洁的写法"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 选取产地为美国或中国大陆的所有电影，并且评分大于9分"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>名字</th>\n",
       "      <th>投票人数</th>\n",
       "      <th>类型</th>\n",
       "      <th>产地</th>\n",
       "      <th>上映时间</th>\n",
       "      <th>时长</th>\n",
       "      <th>年代</th>\n",
       "      <th>评分</th>\n",
       "      <th>首映地点</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>肖申克的救赎</td>\n",
       "      <td>692795.0</td>\n",
       "      <td>剧情/犯罪</td>\n",
       "      <td>美国</td>\n",
       "      <td>1994-09-10 00:00:00</td>\n",
       "      <td>142</td>\n",
       "      <td>1994</td>\n",
       "      <td>9.6</td>\n",
       "      <td>多伦多电影节</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>控方证人</td>\n",
       "      <td>42995.0</td>\n",
       "      <td>剧情/悬疑/犯罪</td>\n",
       "      <td>美国</td>\n",
       "      <td>1957-12-17 00:00:00</td>\n",
       "      <td>116</td>\n",
       "      <td>1957</td>\n",
       "      <td>9.5</td>\n",
       "      <td>美国</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>阿甘正传</td>\n",
       "      <td>580897.0</td>\n",
       "      <td>剧情/爱情</td>\n",
       "      <td>美国</td>\n",
       "      <td>1994-06-23 00:00:00</td>\n",
       "      <td>142</td>\n",
       "      <td>1994</td>\n",
       "      <td>9.4</td>\n",
       "      <td>洛杉矶首映</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>霸王别姬</td>\n",
       "      <td>478523.0</td>\n",
       "      <td>剧情/爱情/同性</td>\n",
       "      <td>中国大陆</td>\n",
       "      <td>1993-01-01 00:00:00</td>\n",
       "      <td>171</td>\n",
       "      <td>1993</td>\n",
       "      <td>9.4</td>\n",
       "      <td>香港</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>泰坦尼克号</td>\n",
       "      <td>157074.0</td>\n",
       "      <td>剧情/爱情/灾难</td>\n",
       "      <td>美国</td>\n",
       "      <td>2012-04-10 00:00:00</td>\n",
       "      <td>194</td>\n",
       "      <td>2012</td>\n",
       "      <td>9.4</td>\n",
       "      <td>中国大陆</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       名字      投票人数        类型    产地                 上映时间   时长    年代   评分  \\\n",
       "0  肖申克的救赎  692795.0     剧情/犯罪    美国  1994-09-10 00:00:00  142  1994  9.6   \n",
       "1    控方证人   42995.0  剧情/悬疑/犯罪    美国  1957-12-17 00:00:00  116  1957  9.5   \n",
       "3    阿甘正传  580897.0     剧情/爱情    美国  1994-06-23 00:00:00  142  1994  9.4   \n",
       "4    霸王别姬  478523.0  剧情/爱情/同性  中国大陆  1993-01-01 00:00:00  171  1993  9.4   \n",
       "5  泰坦尼克号   157074.0  剧情/爱情/灾难    美国  2012-04-10 00:00:00  194  2012  9.4   \n",
       "\n",
       "     首映地点  \n",
       "0  多伦多电影节  \n",
       "1      美国  \n",
       "3   洛杉矶首映  \n",
       "4      香港  \n",
       "5    中国大陆  "
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[((df.产地 == \"美国\") | (df.产地 == \"中国大陆\")) & (df.评分 > 9)][:5]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1.5 缺失值及异常值处理 "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 缺失值处理方法：\n",
    "|**方法**|**说明**|\n",
    "|-:|-:|\n",
    "|**dropna**|根据标签中的缺失值进行过滤，删除缺失值|\n",
    "|**fillna**|对缺失值进行填充|\n",
    "|**isnull**|返回一个布尔值对象，判断哪些值是缺失值|\n",
    "|**notnull**|isnull的否定式|"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 判断缺失值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>名字</th>\n",
       "      <th>投票人数</th>\n",
       "      <th>类型</th>\n",
       "      <th>产地</th>\n",
       "      <th>上映时间</th>\n",
       "      <th>时长</th>\n",
       "      <th>年代</th>\n",
       "      <th>评分</th>\n",
       "      <th>首映地点</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>231</th>\n",
       "      <td>NaN</td>\n",
       "      <td>144.0</td>\n",
       "      <td>纪录片/音乐</td>\n",
       "      <td>韩国</td>\n",
       "      <td>2011-02-02 00:00:00</td>\n",
       "      <td>90</td>\n",
       "      <td>2011</td>\n",
       "      <td>9.7</td>\n",
       "      <td>美国</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>361</th>\n",
       "      <td>NaN</td>\n",
       "      <td>80.0</td>\n",
       "      <td>短片</td>\n",
       "      <td>其他</td>\n",
       "      <td>1905-05-17 00:00:00</td>\n",
       "      <td>4</td>\n",
       "      <td>1964</td>\n",
       "      <td>5.7</td>\n",
       "      <td>美国</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>369</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5315.0</td>\n",
       "      <td>剧情</td>\n",
       "      <td>日本</td>\n",
       "      <td>2004-07-10 00:00:00</td>\n",
       "      <td>111</td>\n",
       "      <td>2004</td>\n",
       "      <td>7.5</td>\n",
       "      <td>日本</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>372</th>\n",
       "      <td>NaN</td>\n",
       "      <td>263.0</td>\n",
       "      <td>短片/音乐</td>\n",
       "      <td>英国</td>\n",
       "      <td>1998-06-30 00:00:00</td>\n",
       "      <td>34</td>\n",
       "      <td>1998</td>\n",
       "      <td>9.2</td>\n",
       "      <td>美国</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>374</th>\n",
       "      <td>NaN</td>\n",
       "      <td>47.0</td>\n",
       "      <td>短片</td>\n",
       "      <td>其他</td>\n",
       "      <td>1905-05-17 00:00:00</td>\n",
       "      <td>3</td>\n",
       "      <td>1964</td>\n",
       "      <td>6.7</td>\n",
       "      <td>美国</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>375</th>\n",
       "      <td>NaN</td>\n",
       "      <td>1193.0</td>\n",
       "      <td>短片/音乐</td>\n",
       "      <td>法国</td>\n",
       "      <td>1905-07-01 00:00:00</td>\n",
       "      <td>10</td>\n",
       "      <td>2010</td>\n",
       "      <td>7.7</td>\n",
       "      <td>美国</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>411</th>\n",
       "      <td>NaN</td>\n",
       "      <td>32.0</td>\n",
       "      <td>短片</td>\n",
       "      <td>其他</td>\n",
       "      <td>1905-05-17 00:00:00</td>\n",
       "      <td>3</td>\n",
       "      <td>1964</td>\n",
       "      <td>7.0</td>\n",
       "      <td>美国</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>432</th>\n",
       "      <td>NaN</td>\n",
       "      <td>1081.0</td>\n",
       "      <td>剧情/动作/惊悚/犯罪</td>\n",
       "      <td>美国</td>\n",
       "      <td>2016-02-26 00:00:00</td>\n",
       "      <td>115</td>\n",
       "      <td>2016</td>\n",
       "      <td>6.0</td>\n",
       "      <td>美国</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>441</th>\n",
       "      <td>NaN</td>\n",
       "      <td>213.0</td>\n",
       "      <td>恐怖</td>\n",
       "      <td>美国</td>\n",
       "      <td>2007-03-06 00:00:00</td>\n",
       "      <td>83</td>\n",
       "      <td>2007</td>\n",
       "      <td>3.2</td>\n",
       "      <td>美国</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>448</th>\n",
       "      <td>NaN</td>\n",
       "      <td>110.0</td>\n",
       "      <td>纪录片</td>\n",
       "      <td>荷兰</td>\n",
       "      <td>2002-04-19 00:00:00</td>\n",
       "      <td>48</td>\n",
       "      <td>2000</td>\n",
       "      <td>9.3</td>\n",
       "      <td>美国</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      名字    投票人数           类型  产地                 上映时间   时长    年代   评分 首映地点\n",
       "231  NaN   144.0       纪录片/音乐  韩国  2011-02-02 00:00:00   90  2011  9.7   美国\n",
       "361  NaN    80.0           短片  其他  1905-05-17 00:00:00    4  1964  5.7   美国\n",
       "369  NaN  5315.0           剧情  日本  2004-07-10 00:00:00  111  2004  7.5   日本\n",
       "372  NaN   263.0        短片/音乐  英国  1998-06-30 00:00:00   34  1998  9.2   美国\n",
       "374  NaN    47.0           短片  其他  1905-05-17 00:00:00    3  1964  6.7   美国\n",
       "375  NaN  1193.0        短片/音乐  法国  1905-07-01 00:00:00   10  2010  7.7   美国\n",
       "411  NaN    32.0           短片  其他  1905-05-17 00:00:00    3  1964  7.0   美国\n",
       "432  NaN  1081.0  剧情/动作/惊悚/犯罪  美国  2016-02-26 00:00:00  115  2016  6.0   美国\n",
       "441  NaN   213.0           恐怖  美国  2007-03-06 00:00:00   83  2007  3.2   美国\n",
       "448  NaN   110.0          纪录片  荷兰  2002-04-19 00:00:00   48  2000  9.3   美国"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[df[\"名字\"].isnull()][:10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>名字</th>\n",
       "      <th>投票人数</th>\n",
       "      <th>类型</th>\n",
       "      <th>产地</th>\n",
       "      <th>上映时间</th>\n",
       "      <th>时长</th>\n",
       "      <th>年代</th>\n",
       "      <th>评分</th>\n",
       "      <th>首映地点</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>肖申克的救赎</td>\n",
       "      <td>692795.0</td>\n",
       "      <td>剧情/犯罪</td>\n",
       "      <td>美国</td>\n",
       "      <td>1994-09-10 00:00:00</td>\n",
       "      <td>142</td>\n",
       "      <td>1994</td>\n",
       "      <td>9.6</td>\n",
       "      <td>多伦多电影节</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>控方证人</td>\n",
       "      <td>42995.0</td>\n",
       "      <td>剧情/悬疑/犯罪</td>\n",
       "      <td>美国</td>\n",
       "      <td>1957-12-17 00:00:00</td>\n",
       "      <td>116</td>\n",
       "      <td>1957</td>\n",
       "      <td>9.5</td>\n",
       "      <td>美国</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>美丽人生</td>\n",
       "      <td>327855.0</td>\n",
       "      <td>剧情/喜剧/爱情</td>\n",
       "      <td>意大利</td>\n",
       "      <td>1997-12-20 00:00:00</td>\n",
       "      <td>116</td>\n",
       "      <td>1997</td>\n",
       "      <td>9.5</td>\n",
       "      <td>意大利</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>阿甘正传</td>\n",
       "      <td>580897.0</td>\n",
       "      <td>剧情/爱情</td>\n",
       "      <td>美国</td>\n",
       "      <td>1994-06-23 00:00:00</td>\n",
       "      <td>142</td>\n",
       "      <td>1994</td>\n",
       "      <td>9.4</td>\n",
       "      <td>洛杉矶首映</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>霸王别姬</td>\n",
       "      <td>478523.0</td>\n",
       "      <td>剧情/爱情/同性</td>\n",
       "      <td>中国大陆</td>\n",
       "      <td>1993-01-01 00:00:00</td>\n",
       "      <td>171</td>\n",
       "      <td>1993</td>\n",
       "      <td>9.4</td>\n",
       "      <td>香港</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       名字      投票人数        类型    产地                 上映时间   时长    年代   评分  \\\n",
       "0  肖申克的救赎  692795.0     剧情/犯罪    美国  1994-09-10 00:00:00  142  1994  9.6   \n",
       "1    控方证人   42995.0  剧情/悬疑/犯罪    美国  1957-12-17 00:00:00  116  1957  9.5   \n",
       "2   美丽人生   327855.0  剧情/喜剧/爱情   意大利  1997-12-20 00:00:00  116  1997  9.5   \n",
       "3    阿甘正传  580897.0     剧情/爱情    美国  1994-06-23 00:00:00  142  1994  9.4   \n",
       "4    霸王别姬  478523.0  剧情/爱情/同性  中国大陆  1993-01-01 00:00:00  171  1993  9.4   \n",
       "\n",
       "     首映地点  \n",
       "0  多伦多电影节  \n",
       "1      美国  \n",
       "2     意大利  \n",
       "3   洛杉矶首映  \n",
       "4      香港  "
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[df[\"名字\"].notnull()][:5]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 填充缺失值 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>名字</th>\n",
       "      <th>投票人数</th>\n",
       "      <th>类型</th>\n",
       "      <th>产地</th>\n",
       "      <th>上映时间</th>\n",
       "      <th>时长</th>\n",
       "      <th>年代</th>\n",
       "      <th>评分</th>\n",
       "      <th>首映地点</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>38738</th>\n",
       "      <td>复仇者联盟3</td>\n",
       "      <td>123456.0</td>\n",
       "      <td>剧情/科幻</td>\n",
       "      <td>美国</td>\n",
       "      <td>2018-05-04 00:00:00</td>\n",
       "      <td>142</td>\n",
       "      <td>2018</td>\n",
       "      <td>NaN</td>\n",
       "      <td>美国</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           名字      投票人数     类型  产地                 上映时间   时长    年代  评分 首映地点\n",
       "38738  复仇者联盟3  123456.0  剧情/科幻  美国  2018-05-04 00:00:00  142  2018 NaN   美国"
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[df[\"评分\"].isnull()][:10] #注意这里特地将前面加入的复仇者联盟令其评分缺失来举例"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>名字</th>\n",
       "      <th>投票人数</th>\n",
       "      <th>类型</th>\n",
       "      <th>产地</th>\n",
       "      <th>上映时间</th>\n",
       "      <th>时长</th>\n",
       "      <th>年代</th>\n",
       "      <th>评分</th>\n",
       "      <th>首映地点</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>38734</th>\n",
       "      <td>1935年</td>\n",
       "      <td>57.0</td>\n",
       "      <td>喜剧/歌舞</td>\n",
       "      <td>美国</td>\n",
       "      <td>1935-03-15 00:00:00</td>\n",
       "      <td>98</td>\n",
       "      <td>1935</td>\n",
       "      <td>7.600000</td>\n",
       "      <td>美国</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>38735</th>\n",
       "      <td>血溅画屏</td>\n",
       "      <td>95.0</td>\n",
       "      <td>剧情/悬疑/犯罪/武侠/古装</td>\n",
       "      <td>中国大陆</td>\n",
       "      <td>1905-06-08 00:00:00</td>\n",
       "      <td>91</td>\n",
       "      <td>1986</td>\n",
       "      <td>7.100000</td>\n",
       "      <td>美国</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>38736</th>\n",
       "      <td>魔窟中的幻想</td>\n",
       "      <td>51.0</td>\n",
       "      <td>惊悚/恐怖/儿童</td>\n",
       "      <td>中国大陆</td>\n",
       "      <td>1905-06-08 00:00:00</td>\n",
       "      <td>78</td>\n",
       "      <td>1986</td>\n",
       "      <td>8.000000</td>\n",
       "      <td>美国</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>38737</th>\n",
       "      <td>列宁格勒围困之星火战役 Блокада: Фильм 2: Ленинградский ме...</td>\n",
       "      <td>32.0</td>\n",
       "      <td>剧情/战争</td>\n",
       "      <td>苏联</td>\n",
       "      <td>1905-05-30 00:00:00</td>\n",
       "      <td>97</td>\n",
       "      <td>1977</td>\n",
       "      <td>6.600000</td>\n",
       "      <td>美国</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>38738</th>\n",
       "      <td>复仇者联盟3</td>\n",
       "      <td>123456.0</td>\n",
       "      <td>剧情/科幻</td>\n",
       "      <td>美国</td>\n",
       "      <td>2018-05-04 00:00:00</td>\n",
       "      <td>142</td>\n",
       "      <td>2018</td>\n",
       "      <td>6.935704</td>\n",
       "      <td>美国</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                      名字      投票人数  \\\n",
       "38734                                              1935年      57.0   \n",
       "38735                                               血溅画屏      95.0   \n",
       "38736                                             魔窟中的幻想      51.0   \n",
       "38737  列宁格勒围困之星火战役 Блокада: Фильм 2: Ленинградский ме...      32.0   \n",
       "38738                                             复仇者联盟3  123456.0   \n",
       "\n",
       "                   类型    产地                 上映时间   时长    年代        评分 首映地点  \n",
       "38734           喜剧/歌舞    美国  1935-03-15 00:00:00   98  1935  7.600000   美国  \n",
       "38735  剧情/悬疑/犯罪/武侠/古装  中国大陆  1905-06-08 00:00:00   91  1986  7.100000   美国  \n",
       "38736        惊悚/恐怖/儿童  中国大陆  1905-06-08 00:00:00   78  1986  8.000000   美国  \n",
       "38737           剧情/战争    苏联  1905-05-30 00:00:00   97  1977  6.600000   美国  \n",
       "38738           剧情/科幻    美国  2018-05-04 00:00:00  142  2018  6.935704   美国  "
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[\"评分\"].fillna(np.mean(df[\"评分\"]), inplace = True) #使用均值来进行替代，inplace意为直接在原始数据中进行修改\n",
    "df[-5:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {},
   "outputs": [],
   "source": [
    "df1 = df.fillna(\"未知电影\") #谨慎使用，除非确定所有的空值都是在一列中，否则所有的空值都会填成这个\n",
    "#不可采用df[\"名字\"].fillna(\"未知电影\")的形式，因为填写后数据格式就变了，变成Series了"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>名字</th>\n",
       "      <th>投票人数</th>\n",
       "      <th>类型</th>\n",
       "      <th>产地</th>\n",
       "      <th>上映时间</th>\n",
       "      <th>时长</th>\n",
       "      <th>年代</th>\n",
       "      <th>评分</th>\n",
       "      <th>首映地点</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Empty DataFrame\n",
       "Columns: [名字, 投票人数, 类型, 产地, 上映时间, 时长, 年代, 评分, 首映地点]\n",
       "Index: []"
      ]
     },
     "execution_count": 92,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1[df1[\"名字\"].isnull()][:10]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 删除缺失值"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "```python\n",
    "df.dropna() 参数\n",
    "\n",
    "how = 'all':删除全为空值的行或列\n",
    "inplace = True: 覆盖之前的数据\n",
    "axis = 0: 选择行或列，默认是行\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "38739"
      ]
     },
     "execution_count": 97,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "metadata": {},
   "outputs": [],
   "source": [
    "df2 = df.dropna()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "38176"
      ]
     },
     "execution_count": 99,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(df2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "metadata": {},
   "outputs": [],
   "source": [
    "df.dropna(inplace = True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "38176"
      ]
     },
     "execution_count": 101,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(df) #inplace覆盖掉原来的值"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 处理异常值\n",
    "\n",
    "异常值，即在数据集中存在不合理的值，又称离群点。比如年龄为-1，笔记本电脑重量为1吨等，都属于异常值的范围。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>名字</th>\n",
       "      <th>投票人数</th>\n",
       "      <th>类型</th>\n",
       "      <th>产地</th>\n",
       "      <th>上映时间</th>\n",
       "      <th>时长</th>\n",
       "      <th>年代</th>\n",
       "      <th>评分</th>\n",
       "      <th>首映地点</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>19777</th>\n",
       "      <td>皇家大贼 皇家大</td>\n",
       "      <td>-80.0</td>\n",
       "      <td>剧情/犯罪</td>\n",
       "      <td>中国香港</td>\n",
       "      <td>1985-05-31 00:00:00</td>\n",
       "      <td>60</td>\n",
       "      <td>1985</td>\n",
       "      <td>6.3</td>\n",
       "      <td>美国</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19786</th>\n",
       "      <td>日本的垃圾去中国大陆 にっぽんの“ゴミ” 大陆へ渡る ～中国式リサイクル錬</td>\n",
       "      <td>-80.0</td>\n",
       "      <td>纪录片</td>\n",
       "      <td>日本</td>\n",
       "      <td>1905-06-26 00:00:00</td>\n",
       "      <td>60</td>\n",
       "      <td>2004</td>\n",
       "      <td>7.9</td>\n",
       "      <td>美国</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19797</th>\n",
       "      <td>女教徒</td>\n",
       "      <td>-118.0</td>\n",
       "      <td>剧情</td>\n",
       "      <td>法国</td>\n",
       "      <td>1966-05-06 00:00:00</td>\n",
       "      <td>135</td>\n",
       "      <td>1966</td>\n",
       "      <td>7.8</td>\n",
       "      <td>美国</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                          名字   投票人数     类型    产地  \\\n",
       "19777                               皇家大贼 皇家大  -80.0  剧情/犯罪  中国香港   \n",
       "19786  日本的垃圾去中国大陆 にっぽんの“ゴミ” 大陆へ渡る ～中国式リサイクル錬  -80.0    纪录片    日本   \n",
       "19797                                    女教徒 -118.0     剧情    法国   \n",
       "\n",
       "                      上映时间   时长    年代   评分 首映地点  \n",
       "19777  1985-05-31 00:00:00   60  1985  6.3   美国  \n",
       "19786  1905-06-26 00:00:00   60  2004  7.9   美国  \n",
       "19797  1966-05-06 00:00:00  135  1966  7.8   美国  "
      ]
     },
     "execution_count": 103,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[df[\"投票人数\"] < 0] #直接删除，或者找原始数据来修正都行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>名字</th>\n",
       "      <th>投票人数</th>\n",
       "      <th>类型</th>\n",
       "      <th>产地</th>\n",
       "      <th>上映时间</th>\n",
       "      <th>时长</th>\n",
       "      <th>年代</th>\n",
       "      <th>评分</th>\n",
       "      <th>首映地点</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>19791</th>\n",
       "      <td>女教师 女教</td>\n",
       "      <td>8.30</td>\n",
       "      <td>剧情/犯罪</td>\n",
       "      <td>日本</td>\n",
       "      <td>1977-10-29 00:00:00</td>\n",
       "      <td>100</td>\n",
       "      <td>1977</td>\n",
       "      <td>6.6</td>\n",
       "      <td>日本</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19804</th>\n",
       "      <td>女郎漫游仙境 ドレミファ娘の血は騒</td>\n",
       "      <td>5.90</td>\n",
       "      <td>喜剧/歌舞</td>\n",
       "      <td>日本</td>\n",
       "      <td>1985-11-03 00:00:00</td>\n",
       "      <td>80</td>\n",
       "      <td>1985</td>\n",
       "      <td>6.7</td>\n",
       "      <td>日本</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19820</th>\n",
       "      <td>女仆日记</td>\n",
       "      <td>12.87</td>\n",
       "      <td>剧情</td>\n",
       "      <td>法国</td>\n",
       "      <td>2015-04-01 00:00:00</td>\n",
       "      <td>96</td>\n",
       "      <td>2015</td>\n",
       "      <td>5.7</td>\n",
       "      <td>法国</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>38055</th>\n",
       "      <td>逃出亚卡拉</td>\n",
       "      <td>12.87</td>\n",
       "      <td>剧情/动作/惊悚/犯罪</td>\n",
       "      <td>美国</td>\n",
       "      <td>1979-09-20 00:00:00</td>\n",
       "      <td>112</td>\n",
       "      <td>1979</td>\n",
       "      <td>7.8</td>\n",
       "      <td>美国</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                      名字   投票人数           类型  产地                 上映时间   时长  \\\n",
       "19791             女教师 女教   8.30        剧情/犯罪  日本  1977-10-29 00:00:00  100   \n",
       "19804  女郎漫游仙境 ドレミファ娘の血は騒   5.90        喜剧/歌舞  日本  1985-11-03 00:00:00   80   \n",
       "19820               女仆日记  12.87           剧情  法国  2015-04-01 00:00:00   96   \n",
       "38055              逃出亚卡拉  12.87  剧情/动作/惊悚/犯罪  美国  1979-09-20 00:00:00  112   \n",
       "\n",
       "         年代   评分 首映地点  \n",
       "19791  1977  6.6   日本  \n",
       "19804  1985  6.7   日本  \n",
       "19820  2015  5.7   法国  \n",
       "38055  1979  7.8   美国  "
      ]
     },
     "execution_count": 107,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[df[\"投票人数\"] % 1 != 0] #小数异常值"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**对于异常值，一般来说数量都会很少，在不影响整体数据分布的情况下，我们直接删除就可以了**\n",
    "\n",
    "**其他属性的异常值处理，我们会在格式转换部分，进一步讨论**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 108,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = df[df.投票人数 > 0]\n",
    "df = df[df[\"投票人数\"] % 1 == 0]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1.6 数据保存 "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 数据处理之后，然后将数据重新保存到movie_data.xlsx "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "metadata": {},
   "outputs": [],
   "source": [
    "df.to_excel(\"movie_data.xlsx\") #默认路径为现在文件夹所在的路径"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}